<template>
  <div class="gInfo_container" v-loading="loading">
    <div class="gInfo_container_top">
      <div class="gInfo_container_top_left">
        <img :src="artistInfo.artist.cover" />
      </div>
      <div class="gInfo_container_top_right">
        <div class="gInfo_container_top_right_name">
          {{ artistInfo.artist.name }}
        </div>
        <div class="gInfo_container_top_right_ENname">
          <span v-for="(item, index) in hotAlbums.artist.alias" :key="index">{{
            item
          }}</span>
        </div>
        <div class="gInfo_container_top_right_list">
          <div class="gInfo_container_top_right_list_inside">
            单曲数:{{ artistInfo.artist.musicSize }}
          </div>
          <div class="gInfo_container_top_right_list_inside">
            专辑数:{{ artistInfo.artist.albumSize }}
          </div>
          <div class="gInfo_container_top_right_list_inside">
            MV数:{{ artistInfo.artist.mvSize }}
          </div>
        </div>
      </div>
    </div>
    <div class="gInfo_container_nav">
      <div
        :class="{ gInfo_container_nav_active: activeIndex == index }"
        class="gInfo_container_nav_inside"
        v-for="(item, index) in nav"
        :key="index"
        @click="changeColor(index)"
      >
        {{ item }}
      </div>
    </div>
    <div class="zhuanJi" v-if="activeIndex == 0">
      <div
        class="zhuanJi_inside"
        v-for="item in hotAlbums.hotAlbums"
        :key="item.id"
        @click="jumpGeDan(item.id)"
      >
        <el-image lazy :src="item.picUrl" />
        <div class="zhuanJi_inside_name">
          <span>{{ item.name }}</span>
          <span class="fuTitle" v-if="item.alias.length != 0">
            (<span v-for="(childItem, index) in item.alias" :key="index">{{
              (index == item.alias.length - 1 && childItem) || childItem + "/"
            }}</span
            >)
          </span>
        </div>
        <div class="zhuanJi_inside_time">
          {{
            new Date(item.publishTime).getFullYear() +
            "-" +
            (new Date(item.publishTime).getMonth() < 10
              ? "0" + new Date(item.publishTime).getMonth()
              : new Date(item.publishTime).getMonth()) +
            "-" +
            (new Date(item.publishTime).getDate() < 10
              ? "0" + new Date(item.publishTime).getDate()
              : new Date(item.publishTime).getDate())
          }}
        </div>
      </div>
    </div>
    <div class="geShou_mv" v-else-if="activeIndex == 1">
      <div class="geShou_mv_inside_no" v-if="mvs.length == 0">暂无MV</div>
      <div v-else class="geShou_mv_inside" v-for="item in mvs" :key="item.id">
        <div
          class="geShou_mv_playCount"
          :style="{ left: item.playCount < 99999 ? '175px' : '180px' }"
        >
          <i style="font-size: 16px" class="el-icon-caret-right" />
          {{
            item.playCount < 99999
              ? item.playCount
              : parseInt(item.playCount / 10000) + "万"
          }}
        </div>
        <div class="geShou_mv_duration">
          {{
            (new Date(item.duration).getMinutes() < 10
              ? "0" + new Date(item.duration).getMinutes()
              : new Date(item.duration).getMinutes()) +
            ":" +
            (new Date(item.duration).getSeconds() < 10
              ? "0" + new Date(item.duration).getSeconds()
              : new Date(item.duration).getSeconds())
          }}
        </div>
        <el-image lazy :src="item.imgurl16v9" />
        <div class="geShou_mv_name">
          {{ item.name }}
        </div>
      </div>
    </div>
    <div class="artist_info" v-else-if="activeIndex == 2">
      <div class="geShou_mv_inside_no" v-if="artistDescArry.introduction.length == 0">
        暂无歌手详情
      </div>
      <div
        v-else
        class="artist_info_inside"
        v-for="(item, index) in artistDescArry.introduction"
        :key="index"
      >
        <div class="artist_info_inside_title">{{ item.ti }}</div>
        <div
          class="artist_info_inside_contact"
          v-for="(childItem, index) in item.txt"
          :key="index"
        >
          {{ childItem }}
        </div>
      </div>
    </div>
    <div v-else class="Similar_singer">
      <div class="geShou_mv_inside_no" v-if="artistsList.length == 0">无</div>
      <div
        v-else
        class="Similar_singer_inside"
        @click="jumpUrl(item.id)"
        v-for="item in artistsList"
        :key="item.id"
      >
        <el-image lazy :src="item.picUrl" />
        <div class="Similar_singer_inside_name">{{ item.name }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  artistDetail,
  simiArtist,
  artistAlbum,
  artistMv,
  artistDesc,
} from "../../../api/index";
export default {
  inject: ["reload"],
  created() {
    this.loading = true;
    artistDetail({ id: this.$route.query.id }).then((res) => {
      this.artistInfo = res.data;
      simiArtist({ id: this.$route.query.id }).then((res) => {
        this.artistsList = res.artists;
        artistAlbum({ id: this.$route.query.id, limit: 40 }).then((res) => {
          this.hotAlbums = res;
          artistMv({ id: this.$route.query.id }).then((res) => {
            this.mvs = res.mvs;
            artistDesc({ id: this.$route.query.id }).then((res) => {
              this.artistDescArry = res;
              for (
                let i = 0;
                i < this.artistDescArry.introduction.length;
                i++
              ) {
                this.artistDescArry.introduction[i].txt =
                  this.artistDescArry.introduction[i].txt
                    .replace(/\n/g, "<br/>")
                    .split("<br/>");
              }
              this.loading = false;
            });
          });
        });
      });
    });
  },
  data() {
    return {
      loading: false,
      artistInfo: { artist: {} },
      nav: ["专辑", "MV", "歌手详情", "相似歌手"],
      activeIndex: 0,
      artistsList: [],
      mvs: [],
      hotAlbums: { artist: { alias: [] } },
      artistDescArry: { introduction: [] },
    };
  },
  methods: {
    jumpGeDan(id) {
      this.$router.push({
        path: "/zhuanJi",
        query: {
          id
        },
      });
    },
    changeColor(index) {
      this.activeIndex = index;
    },
    jumpUrl(id) {
      this.$router.push({
        path: "/geShou",
        query: {
          id,
        },
      });
      this.reload();
    },
  },
};
</script>

<style lang="scss" scoped>
@import "../../../common/css/commonStyle";
.gInfo_container {
  width: 95%;
  padding-top: 20px;
  .gInfo_container_top {
    margin-bottom: 35px;
    display: flex;
    justify-content: space-between;
    .gInfo_container_top_left {
      width: 25%;
      height: 180px;
      img {
        width: 100%;
        height: 100%;
        border-radius: 5px;
      }
    }
    .gInfo_container_top_right {
      width: 70%;
      .gInfo_container_top_right_name {
        margin-top: 5px;
        font-size: 22px;
        font-weight: 900;
        margin-bottom: 20px;
      }
      .gInfo_container_top_right_ENname {
        font-size: 14px;
        font-weight: 200;
        margin-bottom: 30px;
      }
      .gInfo_container_top_right_list {
        width: 250px;
        font-size: 14px;
        font-weight: 200;
        display: flex;
        justify-content: space-between;
      }
    }
  }
  .gInfo_container_nav {
    width: 300px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    .gInfo_container_nav_inside {
      font-size: 18px;
      font-weight: 200;
      cursor: pointer;
    }
    .gInfo_container_nav_active {
      cursor: default;
      font-size: 22px;
      font-weight: 800;
      border-bottom: 4px solid $wangYiYunColor;
    }
  }
  .zhuanJi {
    display: flex;
    // justify-content: space-around;
    flex-wrap: wrap;
    .zhuanJi_inside {
      margin-right: 15px;
      cursor: pointer;
      width: 23%;
      margin-bottom: 30px;
      .el-image {
        width: 100%;
        height: 185px;
        margin-bottom: 10px;
      }
      .zhuanJi_inside_name {
        margin-bottom: 10px;
        font-size: 15px;
        .fuTitle {
          color: #909399;
        }
      }
      .zhuanJi_inside_time {
        color: #909399;
        font-size: 14px;
      }
    }
  }
  .geShou_mv {
    display: flex;
    flex-wrap: wrap;
    .geShou_mv_inside_no {
      @include flex;
      width: 100%;
      height: 300px;
    }
    .geShou_mv_inside {
      width: 30%;
      margin-bottom: 30px;
      margin-right: 25px;
      .el-image {
        width: 100%;
        height: 150px;
        border-radius: 5px;
        margin-bottom: 10px;
      }
      .geShou_mv_playCount {
        display: flex;
        font-size: 14px;
        position: relative;
        color: whitesmoke;
        bottom: 205px;
      }
      .geShou_mv_duration {
        font-size: 14px;
        position: relative;
        color: whitesmoke;
        bottom: 93px;
        left: 190px;
      }
      .geShou_mv_name {
        @include white_space;
        font-size: 14px;
      }
    }
  }
  .artist_info {
    .geShou_mv_inside_no {
      @include flex;
      width: 100%;
      height: 300px;
    }
    .artist_info_inside {
      margin-bottom: 50px;
      .artist_info_inside_title {
        font-weight: 600;
        margin-bottom: 10px;
      }
      .artist_info_inside_contact {
        margin-bottom: 10px;
        color: #909399;
        font-size: 14px;
        text-indent: 2em;
      }
    }
  }
  .Similar_singer {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    .geShou_mv_inside_no {
      @include flex;
      width: 100%;
      height: 300px;
    }
    .Similar_singer_inside {
      cursor: pointer;
      width: 18%;
      margin-bottom: 30px;
      .el-image {
        margin-bottom: 10px;
        border-radius: 5px;
      }
      .Similar_singer_inside_name {
        font-size: 14px;
      }
    }
  }
}
</style>
